<?php
namespace app\admin\model;

use think\Model;
use traits\model\SoftDelete;

class Volunteer extends Model
{

    use SoftDelete;
    // 表名
    protected $name = 'volunteer';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'service_time_type_text',
        'affiliated_center_text',
        'id_card_hk',
    ];

    public function getServiceTimeTypeList()
    {
        return ['1' => __('Service_time_type 1'), '2' => __('Service_time_type 2')];
    }

    public function getServiceTimeTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['service_time_type']) ? $data['service_time_type'] : '');
        $list  = $this->getServiceTimeTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getIdCardHkAttr($value, $data)
    {

        return $data['id_card_front'] . $data['id_card'] . '(' . $data['id_card_after'] . ')';
    }
    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function volunteerspecialty()
    {
        return $this->belongsTo('VolunteerSpecialty', 'volunteer_specialty_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function staff()
    {
        return $this->belongsTo('Staff', 'staff_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function getAffiliatedCenterTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['affiliated_center_id']) ? $data['affiliated_center_id'] : '');
        $list  = db('area')->column('id,name');
        return isset($list[$value]) ? $list[$value] : '';
    }
}
